﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace DemoAstarAlgorithm
{
    class cLetter : cSprite
    {
        int m_iNox = 55;
        int m_iNoy = 66;
        Rectangle No0s, No1s, No2s, No3s, No4s, No5s, No6s, No7s, No8s, No9s;

        public cLetter(ContentManager content, Vector2 newposition) : base(newposition)
        {
            m_tTexture = content.Load<Texture2D>(@"images/so-score");
            No0s = new Rectangle(495, 0, m_iNox, m_iNoy);
            No1s = new Rectangle(0, 0, m_iNox, m_iNoy);
            No2s = new Rectangle(55, 0, m_iNox, m_iNoy);
            No3s = new Rectangle(110, 0, m_iNox, m_iNoy);
            No4s = new Rectangle(165, 0, m_iNox, m_iNoy);
            No5s = new Rectangle(220, 0, m_iNox, m_iNoy);
            No6s = new Rectangle(275, 0, m_iNox, m_iNoy);
            No7s = new Rectangle(330, 0, m_iNox, m_iNoy);
            No8s = new Rectangle(385, 0, m_iNox, m_iNoy);
            No9s = new Rectangle(440, 0, m_iNox, m_iNoy);
        }

        public void Draw(SpriteBatch spriteBatch, string str, float X, float Y, int width)
        {
            float m_fx;
            float m_fy = Y;
            int m_iIDLetter = 0;
            int m_iLength = str.Length;
            int i = 0;
            if (m_iLength == 1)
                m_fx = X;
            else
                if (m_iLength == 2)
                    m_fx = X - width / 2;
                else
                    m_fx = X - width;
            while (i < m_iLength)
            {
                char c = str[i];
                m_iIDLetter = (int)c - 48;
                m_fx += width;
                switch (m_iIDLetter)
                {
                    case 0:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No0s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No0s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 1:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No1s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No1s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 2:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No2s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No2s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 3:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No3s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No3s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 4:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No4s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No4s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 5:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No5s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No5s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 6:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No6s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No6s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 7:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No7s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No7s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 8:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No8s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No8s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    case 9:
                        if (width < 50)
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)20, (int)25), No9s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        else
                            spriteBatch.Draw(m_tTexture, new Rectangle((int)m_fx, (int)m_fy, (int)55, (int)66), No9s, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                        break;
                    default:
                        break;
                }
                i++;
            }
        }
    }
}
